<template>
  <div class="echart" id="echart"></div>
</template>

<script setup>
import * as echarts from 'echarts'
import { onMounted, onUnmounted, ref } from 'vue'
let echart = ref(null)
onMounted(() => {
  if (echart.value) {
    echart.value.dispose()
  }
  let option = {
    tooltip: {},
    legend: {
      data: ['销量']
    },
    xAxis: {
      type: 'category',
      data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
    },
    yAxis: {
      type: 'value'
    },
    series: [
      {
        name: '销量',
        type: 'bar',
        data: [5, 20, 36, 10, 10, 20]
      }
    ]
  }
  echart.value = echarts.init(document.getElementById('echart'))
  echart.value.setOption(option)
})

onUnmounted(() => {
  echart.value.dispose()
})
</script>

<style lang="scss" scoped>
.echart {
  width: 100%;
  height: 100%;
}
</style>